package com.charlie.beans;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Вова
 */
@Entity
@Table(name = "ROLES")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Roles.findAll", query = "SELECT r FROM Roles r"),
    @NamedQuery(name = "Roles.findByRolesId", query = "SELECT r FROM Roles r WHERE r.rolesId = :rolesId"),
    @NamedQuery(name = "Roles.findByRolesName", query = "SELECT r FROM Roles r WHERE r.rolesName = :rolesName")})
public class Roles implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ROLES_SEQ")
    @SequenceGenerator(name = "ROLES_SEQ", sequenceName = "ROLES_ROLES_ID_SEQ", allocationSize = 1)
    @Column(name = "ROLES_ID")
    private Integer rolesId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "ROLES_NAME")
    private String rolesName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolesId")
    private Collection<UsersRole> usersRoleCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolesId")
    private Collection<GroupsRoles> groupsRolesCollection;

    public Roles() {
    }

    public Roles(Integer rolesId) {
        this.rolesId = rolesId;
    }

    public Roles(Integer rolesId, String rolesName) {
        this.rolesId = rolesId;
        this.rolesName = rolesName;
    }

    public Integer getRolesId() {
        return rolesId;
    }

    public void setRolesId(Integer rolesId) {
        this.rolesId = rolesId;
    }

    public String getRolesName() {
        return rolesName;
    }

    public void setRolesName(String rolesName) {
        this.rolesName = rolesName;
    }

    @XmlTransient
    public Collection<UsersRole> getUsersRoleCollection() {
        return usersRoleCollection;
    }

    public void setUsersRoleCollection(Collection<UsersRole> usersRoleCollection) {
        this.usersRoleCollection = usersRoleCollection;
    }

    @XmlTransient
    public Collection<GroupsRoles> getGroupsRolesCollection() {
        return groupsRolesCollection;
    }

    public void setGroupsRolesCollection(Collection<GroupsRoles> groupsRolesCollection) {
        this.groupsRolesCollection = groupsRolesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rolesId != null ? rolesId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Roles)) {
            return false;
        }
        Roles other = (Roles) object;
        if ((this.rolesId == null && other.rolesId != null) || (this.rolesId != null && !this.rolesId.equals(other.rolesId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.charlie.beans.Roles[ rolesId=" + rolesId + " ]";
    }
    
}
